local x=2
local z=2*`x'
local zz=3*`x'
gen chngsalepricefull=chngsaleprice
replace chngcontract=. if common2!=1
replace chngsaleprice=. if common2!=1


gen coeff=.
gen seup=.
gen selow=.

newey chngcontract  F.chngstock  L`x'.chngcontract L`z'.chngcontract L`zz'.chngcontract _I* ,lag(4)
replace coeff=_b[F.chngstock] in 1
replace seup=_b[F.chngstock]+1.645*_se[F.chngstock] in 1
replace selow=_b[F.chngstock]-1.645*_se[F.chngstock] in 1

newey chngcontract  chngstock  L`x'.chngcontract L`z'.chngcontract L`zz'.chngcontract _I* ,lag(4)
replace coeff=_b[chngstock] in 2
replace seup=_b[chngstock]+1.645*_se[chngstock] in 2
replace selow=_b[chngstock]-1.645*_se[chngstock] in 2

local k=3
forvalues j=1/6{
newey chngcontract  L`j'.chngstock  L`x'.chngcontract L`z'.chngcontract L`zz'.chngcontract _I* ,lag(4)
replace coeff=_b[L`j'.chngstock] in `k'
replace seup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace selow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}


forvalues j=7/8{
newey chngcontract  L`j'.chngstock  L`x'.chngcontract L`z'.chngcontract L`zz'.chngcontract L8.chngcontract _I* ,lag(4)
replace coeff=_b[L`j'.chngstock] in `k'
replace seup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace selow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}
forvalues j=9/10{
newey chngcontract  L`j'.chngstock  L`x'.chngcontract L`z'.chngcontract L`zz'.chngcontract L8.chngcontract L10.chngcontract _I* ,lag(4)
replace coeff=_b[L`j'.chngstock] in `k'
replace seup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace selow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}

forvalues j=11/12{
newey chngcontract  L`j'.chngstock  L`x'.chngcontract L`z'.chngcontract L`zz'.chngcontract L8.chngcontract L10.chngcontract L12.chngcontract _I* ,lag(4)
replace coeff=_b[L`j'.chngstock] in `k'
replace seup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace selow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}

forvalues j=13/14{
newey chngcontract  L`j'.chngstock  L`x'.chngcontract L`z'.chngcontract L`zz'.chngcontract L8.chngcontract L10.chngcontract L12.chngcontract L14.chngcontract _I* ,lag(4)
replace coeff=_b[L`j'.chngstock] in `k'
replace seup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace selow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}

forvalues j=15/16{
newey chngcontract  L`j'.chngstock  L`x'.chngcontract L`z'.chngcontract L`zz'.chngcontract L8.chngcontract L10.chngcontract L12.chngcontract L14.chngcontract L16.chngcontract _I* ,lag(4)
replace coeff=_b[L`j'.chngstock] in `k'
replace seup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace selow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}









gen spcoeff=.
gen spseup=.
gen spselow=.

newey chngsaleprice  F.chngstock  L`x'.chngsaleprice L`z'.chngsaleprice L`zz'.chngsaleprice _I* ,lag(4)
replace spcoeff=_b[F.chngstock] in 1
replace spseup=_b[F.chngstock]+1.645*_se[F.chngstock] in 1
replace spselow=_b[F.chngstock]-1.645*_se[F.chngstock] in 1

newey chngsaleprice  chngstock  L`x'.chngsaleprice L`z'.chngsaleprice L`zz'.chngsaleprice _I* ,lag(4)
replace spcoeff=_b[chngstock] in 2
replace spseup=_b[chngstock]+1.645*_se[chngstock] in 2
replace spselow=_b[chngstock]-1.645*_se[chngstock] in 2

local k=3
forvalues j=1/6{
newey chngsaleprice  L`j'.chngstock  L`x'.chngsaleprice L`z'.chngsaleprice L`zz'.chngsaleprice _I* ,lag(4)
replace spcoeff=_b[L`j'.chngstock] in `k'
replace spseup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace spselow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}


forvalues j=7/8{
newey chngsaleprice  L`j'.chngstock  L`x'.chngsaleprice L`z'.chngsaleprice L`zz'.chngsaleprice L8.chngsaleprice _I* ,lag(4)
replace spcoeff=_b[L`j'.chngstock] in `k'
replace spseup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace spselow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}
forvalues j=9/10{
newey chngsaleprice  L`j'.chngstock  L`x'.chngsaleprice L`z'.chngsaleprice L`zz'.chngsaleprice L8.chngsaleprice L10.chngsaleprice _I* ,lag(4)
replace spcoeff=_b[L`j'.chngstock] in `k'
replace spseup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace spselow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}

forvalues j=11/12{
newey chngsaleprice  L`j'.chngstock  L`x'.chngsaleprice L`z'.chngsaleprice L`zz'.chngsaleprice L8.chngsaleprice L10.chngsaleprice L12.chngsaleprice _I* ,lag(4)
replace spcoeff=_b[L`j'.chngstock] in `k'
replace spseup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace spselow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}

forvalues j=13/14{
newey chngsaleprice  L`j'.chngstock  L`x'.chngsaleprice L`z'.chngsaleprice L`zz'.chngsaleprice L8.chngsaleprice L10.chngsaleprice L12.chngsaleprice L14.chngsaleprice _I* ,lag(4)
replace spcoeff=_b[L`j'.chngstock] in `k'
replace spseup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace spselow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}

forvalues j=15/16{
newey chngsaleprice  L`j'.chngstock  L`x'.chngsaleprice L`z'.chngsaleprice L`zz'.chngsaleprice L8.chngsaleprice L10.chngsaleprice L12.chngsaleprice L14.chngsaleprice L16.chngsaleprice _I* ,lag(4)
replace spcoeff=_b[L`j'.chngstock] in `k'
replace spseup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace spselow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}




gen spfullcoeff=.
gen spfullseup=.
gen spfullselow=.

newey chngsalepricefull  F.chngstock  L`x'.chngsalepricefull L`z'.chngsalepricefull L`zz'.chngsalepricefull _I* ,lag(4)
replace spfullcoeff=_b[F.chngstock] in 1
replace spfullseup=_b[F.chngstock]+1.645*_se[F.chngstock] in 1
replace spfullselow=_b[F.chngstock]-1.645*_se[F.chngstock] in 1

newey chngsalepricefull  chngstock  L`x'.chngsalepricefull L`z'.chngsalepricefull L`zz'.chngsalepricefull _I* ,lag(4)
replace spfullcoeff=_b[chngstock] in 2
replace spfullseup=_b[chngstock]+1.645*_se[chngstock] in 2
replace spfullselow=_b[chngstock]-1.645*_se[chngstock] in 2

local k=3
forvalues j=1/6{
newey chngsalepricefull  L`j'.chngstock  L`x'.chngsalepricefull L`z'.chngsalepricefull L`zz'.chngsalepricefull _I* ,lag(4)
replace spfullcoeff=_b[L`j'.chngstock] in `k'
replace spfullseup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace spfullselow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}


forvalues j=7/8{
newey chngsalepricefull  L`j'.chngstock  L`x'.chngsalepricefull L`z'.chngsalepricefull L`zz'.chngsalepricefull L8.chngsalepricefull _I* ,lag(4)
replace spfullcoeff=_b[L`j'.chngstock] in `k'
replace spfullseup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace spfullselow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}
forvalues j=9/10{
newey chngsalepricefull  L`j'.chngstock  L`x'.chngsalepricefull L`z'.chngsalepricefull L`zz'.chngsalepricefull L8.chngsalepricefull L10.chngsalepricefull _I* ,lag(4)
replace spfullcoeff=_b[L`j'.chngstock] in `k'
replace spfullseup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace spfullselow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}

forvalues j=11/12{
newey chngsalepricefull  L`j'.chngstock  L`x'.chngsalepricefull L`z'.chngsalepricefull L`zz'.chngsalepricefull L8.chngsalepricefull L10.chngsalepricefull L12.chngsalepricefull _I* ,lag(4)
replace spfullcoeff=_b[L`j'.chngstock] in `k'
replace spfullseup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace spfullselow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}

forvalues j=13/14{
newey chngsalepricefull  L`j'.chngstock  L`x'.chngsalepricefull L`z'.chngsalepricefull L`zz'.chngsalepricefull L8.chngsalepricefull L10.chngsalepricefull L12.chngsalepricefull L14.chngsalepricefull _I* ,lag(4)
replace spfullcoeff=_b[L`j'.chngstock] in `k'
replace spfullseup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace spfullselow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}

forvalues j=15/16{
newey chngsalepricefull  L`j'.chngstock  L`x'.chngsalepricefull L`z'.chngsalepricefull L`zz'.chngsalepricefull L8.chngsalepricefull L10.chngsalepricefull L12.chngsalepricefull L14.chngsalepricefull L16.chngsalepricefull _I* ,lag(4)
replace spfullcoeff=_b[L`j'.chngstock] in `k'
replace spfullseup=_b[L`j'.chngstock]+1.645*_se[L`j'.chngstock] in `k'
replace spfullselow=_b[L`j'.chngstock]-1.645*_se[L`j'.chngstock] in `k'
local k=`k'+1
}


gen index=_n-2


line coeff seup selow index if coeff!=., lcolor(black black black) lpattern(l - - ) xlabel(-1 (1) 16) title("Contract-Dated Index") saving(contract.gph,replace) ylabel(-0.25 (.1) 0.35) yline(0,lcolor(black)) legend(off) xtitle("Number of Lags (in weeks)")
line spcoeff spseup spselow index if coeff!=., lcolor(black black black) lpattern(l - - ) xlabel(-1 (1) 16) title("Closing-Dated Index")  saving(saleprice.gph,replace) ylabel(-0.25 (.1) 0.35) yline(0,lcolor(black)) legend(off)  xtitle("Number of Lags (in weeks)")
line spfullcoeff spfullseup spfullselow index if coeff!=.,lcolor(black black black) lpattern(l - - ) xlabel(-1 (1) 16) title("Closing-Dated (Full Sample)")  saving(salepricefull.gph,replace) ylabel(-0.25 (.1) 0.35) yline(0,lcolor(black)) legend(off)  xtitle("Number of Lags (in weeks)")
graph combine contract.gph saleprice.gph salepricefull.gph,rows(2)
graph export irf_stock.ps,replace logo(off)
!ps2pdf irf_stock.ps irf_stock.pdf
